package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo9 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection();) {
            connection.setAutoCommit(false);
            String sql = "UPDATE user " +
                    "SET password=?,nickname=?,age=? " +
                    "WHERE id=?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,"789456");
            ps.setString(2,"帅狗");
            ps.setInt(3,58);
            ps.setInt(4,1);
            int num = ps.executeUpdate();
            System.out.println(num>0?"修改成功":"修改失败");
            connection.commit();
            System.out.println("回滚了");
            connection.rollback();
            System.out.println("提交了");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
